#ifndef QLIB_COMPONENTPINMANAGER_H
#define QLIB_COMPONENTPINMANAGER_H

#include <QtGui/qsyntaxhighlighter.h>
#include <QtGui/qwidget.h>

/*namespace PinManager {
    const char GROUP_PATTERN[] = "^[^:\\s]+:";
    const char COMMENT_PATTERN[] = "//[^\n]*";
}*/

QT_FORWARD_DECLARE_CLASS(QComboBox)
QT_FORWARD_DECLARE_CLASS(QPlainTextEdit)

class PinSyntaxHighlighter : public QSyntaxHighlighter
{
    Q_OBJECT
public:
    PinSyntaxHighlighter(QTextDocument *parent);

    bool parse(const QString &text);
    const QString &parseError() { return m_parseError; }

    bool hasGroup() { return (m_elements["Group"].index >= 0); }
    int groupIndex() { return m_elements["Group"].index; }
    const QString &group() { return m_elements["Group"].text; }

    bool hasComment() { return (m_elements["Comment"].index >= 0); }
    int commentIndex() { return m_elements["Comment"].index; }
    const QString &comment() { return m_elements["Comment"].text; }

protected:
    void highlightBlock(const QString &text);

private:
    struct ParseElement
    {
        int              index;
        QString          text;
        QTextCharFormat  format;
        QString          pattern;
    };

    QString                      m_parseError;

    QHash<QString,ParseElement>  m_elements;
    //int          m_groupIndex;
    //QString      m_group;
    //int          m_commentIndex;
    //QString      m_comment;
};

class ComponentPinManager : public QWidget
{
    Q_OBJECT
public:
    explicit ComponentPinManager(QWidget *parent = 0);

    
signals:
    
public slots:
private:
    QComboBox               *m_group;
    QPlainTextEdit          *m_pinList;
    PinSyntaxHighlighter    *m_highlignter;
};

#endif // COMPONENTPINMANAGER_H
